#include <iostream>
#include<functional>
#include"concrete_implementor.h"
#include"refined_abstraction.h"
using namespace std;
using namespace std::placeholders;

#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if(p){delete(p); (p)=NULL;} }
#endif

void DisplayAndDestory(IElectricalEquipment *lhs,ISwitch *rhs){
    rhs->on();
    rhs->off();
    SAFE_DELETE(lhs);
    SAFE_DELETE(rhs);
    cout<<endl;
}

int main()
{

    IElectricalEquipment *iee=new TV();
    ISwitch *iswi=new PullChainSwitch(iee);
    auto dad=std::bind(DisplayAndDestory,iee,iswi);
    dad();


    iee=new Light();
    iswi=new TwoPositionSwitch(iee);
    dad();

    iee=new Fan();
    iswi=new TwoPositionSwitch(iee);
    dad();
    return 0;
}
